$(document)
	.ready(
			function() {
				$('#loginForm')
						.bootstrapValidator(
								{
									message : '值校验失败',
									feedbackIcons : {
										//valid : 'glyphicon glyphicon-ok',
										//invalid : 'glyphicon glyphicon-remove',
										//validating : 'glyphicon glyphicon-refresh'
									},
									fields : {
										username : {
											message : '用户名校验失败',
											validators : {
												notEmpty : {
													message : '用户名不能为空!'
												},
												stringLength : {
													min : 6,
													max : 30,
													message : '用户名长度最短6位,最长30'
												}
											}
										},
										password : {
											validators : {
												notEmpty : {
													message : '密码不能为空!'
												}
											}
										},
										imgCode : {
											validators : {
												notEmpty : {
													message : '验证码不能为空!'
												}
											}
										}
									}
								}).on('success.form.bv', function(e) {
						            e.preventDefault();
						            var $form     = $(e.target),
						            validator = $form.data('bootstrapValidator');
						            
						           var requestData=$("#loginForm").serialize(); 
						            var ajax = $.post("/login/submit",requestData, function(data) {
						            
						                if(data.valid == false){
						                	//var msg = validator.getFieldElements('username').val();
						                	$form.find('.alert').html(data.msg).show();
						                }else{
						                	$form.find('.alert').html(data.msg+'。。。请等待跳转到原页面').show();
						                	var from = getQueryString('from');
						                	if(from == null){
						                		from = '/';
						                	}
						                	setTimeout('self.location="'+from+'"',1000);
						                	
						                }
						              },'JSON');
						            

						        });
			});
		
	function getQueryString(name) { 
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
		var r = window.location.search.substr(1).match(reg); 
		if (r != null) return unescape(r[2]); return null; 
	} 
	
	function reloadImg(){		
		 $('#imgView').attr({
             src: $('#imgView').data('url')+'?t='+Math.random()
         });
		
	}